<?php
/*
Template Name: Event
*/
get_header();

global $wp_query;
    $event = $wp_query->get_queried_object();
    $event_name = $event->name;
    $event_id = $event->term_id;
    $event_des = $event->description;
?>
<div class="row-fluid" id="category-wrap">
        <h1><p><?php echo $event_name;?> Coupon & Promo Codes</p></h1>
        <div class="row-fluid wrap-des truncated">
            <p class="category-description"><?php echo $event_des;?> <span href="#" class="less_desc"> « Less</span></p>
            <span href="#" class="more_desc">More »</span>
        </div>
</div>
<div class="row-fluid">
    <div class="span8 content-sidebar">
        <div class="row-fluid flex_slider">
            <?php if(is_active_sidebar('cs-content-sidebar')) dynamic_sidebar( 'cs-content-sidebar' ); ?>
        </div>
        <div class="row-fluid boxf">
            <div class="row-fluid header-coupon">
                  <div class="span12 code-coupon"><h2>Current Top <?php echo $event_name;?> Coupons</h2></div>
            </div>
        <?php
            $page = get_option('pagination_tax_event');
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            //$date = date('Y/m/d');
            $meta_query = array(
                        array('key'=>'active_metadata', 'value'=>'active', 'compare' => '=')
                        //,array('key'=>'expire_date_metadata', 'value'=>$date, 'compare' => '>')
                    );
            $args = array(
                'post_type' => 'coupon',
                'post_status' =>'publish',
                'posts_per_page' => $page,
                'paged' => $paged,
                'orderby' => 'date',
                'order' => 'desc',
                'meta_query' => $meta_query,
                'tax_query' => array(
                'relation' => 'AND',
                     array(
                           'taxonomy' => 'event',
                           'field' => 'id',
                           'terms' => $event_id,
                           'operator' => 'IN'
                    )
                )
            );
            $wp_query = new WP_Query($args);
            $coupons = $wp_query->posts;
            $total_pages = $wp_query->max_num_pages;
            foreach ($coupons as $v){
                $cp_id = $v->ID;
                cpx_get_coupon_detail_2($cp_id);
            }?>
                 <?php 
                    if($total_pages > 0){
                        pagination($total_pages,2);
                    }
                    else{ ?>
                    <div class="row-fluid notfound">
                        <span>The coupon you need is not available in this event.</span>
                        <p>But you should see these coupons below or go.</p>
                    </div>
                    <?php 
                        $page_op = get_option('pagination_404');
                        cpx_get_coupon_detail_3('','',$page_op);
                    }
                 ?>
            </div>
        </div>
        <div class="span4 right-sidebar">
            <?php if(is_active_sidebar('cs-event-sidebar')) dynamic_sidebar( 'cs-event-sidebar' ); ?>
        </div>
</div>
<div class="row-fluid top-store-category">
     <?php if(is_active_sidebar('cs-text-link-sidebar')) dynamic_sidebar( 'cs-text-link-sidebar' ); ?>
</div>
<?php get_footer(); ?>